home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / misc / byteswap.c next >
C/C++ Source or Header  |  1998-03-03  |  2KB  |  57 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: /usr/CVS/descent/misc/byteswap.c,v $
  15.  * $Revision: 1.1.1.1 $
  16.  * $Author: nobody $
  17.  * $Date: 1998/03/03 15:12:42 $
  18.  *
  19.  * code to swap bytes because of big/little endian problems.
  20.  * 
  21.  * $Log: byteswap.c,v $
  22.  * Revision 1.1.1.1  1998/03/03 15:12:42  nobody
  23.  * reimport after crash from backup
  24.  *
  25.  * Revision 1.1.1.1  1998/02/13  20:21:17  hfrieden
  26.  * Initial Import
  27.  *
  28.  * Revision 1.3  1995/08/18  15:51:17  allender
  29.  * put back in old byteswapping code
  30.  *
  31.  * Revision 1.2  1995/05/04  20:10:06  allender
  32.  * use unsigned to prevent sign problems
  33.  *
  34.  * Revision 1.1  1995/03/30  15:01:49  allender
  35.  * Initial revision
  36.  *
  37. */
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41.  
  42. #include <sys/types.h>
  43.  
  44. ushort swapshort(ushort s)
  45. {
  46.     return ((s >> 8) & 0x00ff) | ((s << 8) & 0xff00);
  47. }
  48.  
  49. uint swapint(uint i)
  50. {
  51.     ushort s1, s2;
  52.     
  53.     s1 = (i >> 16) & 0x0000ffff;
  54.     s2 = i & 0x0000ffff;
  55.     return ((swapshort(s2) << 16) | swapshort(s1));
  56. }
  57.